<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Activities extends MY_Controller {

	function __construct(){
		parent::__construct();
	}
	function index(){
		
		$act_url=$this->uri->segment(3);
		$this->view($act_url);
	}
	
	function apply(){
		if($this->input->is_ajax_request()){
			$post=$this->input->post(NULL,TRUE);
			if(!empty($post)){
				if(empty($post['name'])){
					$result['errorcode']=1;
					$result['error']='请输入姓名';
					echo json_encode($result);
					exit;
				}
				$data=array_intersect_key($post,array('company'=>'','brand'=>'','name'=>'','position'=>'','phone'=>'','email'=>'','weixin'=>'','activityname'=>''));
				$needs=array();
				$needs=$post['needs'];
				if(in_array('7',$needs)) $data['other']=$post['other']; 
				$data['needs']=implode(',',$needs);
				$data['addtime']=time();
				if($this->Data_model->addData($data,'actapply')){
					$result['errorcode']=0;
					$result['message']='恭喜你，报名成功！';
					$result['url']=site_url('activities/apply');
				}else{
					$result['errorcode']=1;
					$result['error']='亲，报名失败，请联系我们！';
				}
				echo json_encode($result);		
			}else{
				$this->view('apply');
			}
		}else{
			$this->view('apply');
		}
	}
	
}